//
//  ShopsMentViewController.m
//  何五路
//
//  Created by _ADY on 15/8/14.
//  Copyright (c) 2015年 _ADY. All rights reserved.
//

#import "ShopsMentViewController.h"

@interface ShopsMentViewController ()

@end
static LoadingView *loading = nil;

#define settlementhight  192/2
#define shopsHight 60
@implementation ShopsMentViewController
@synthesize mTableView,allArray,idStr,shopsInt;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    self.view.backgroundColor = bgColor;
    
    mTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, screenMySize.size.width, screenMySize.size.height-60) style:UITableViewStyleGrouped];
    mTableView.delegate = self;
    mTableView.dataSource = self;
    mTableView.sectionHeaderHeight = 0.0;
    mTableView.sectionFooterHeight = 0.0;
    mTableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:mTableView];
    
    UIView *v = [[UIView alloc] initWithFrame:CGRectZero];//清除多余分割线
    [mTableView setTableFooterView:v];
    
    [self myBarView];
}

-(void)myBarView
{
    UIView *barView = [[UIView alloc] initWithFrame:CGRectMake(0, screenMySize.size.height-60, screenMySize.size.width, 60)];
    barView.backgroundColor = [UIColor colorWithWhite:0 alpha:.8];
    [self.view addSubview:barView];

    NSArray *tArray = [NSArray arrayWithObjects:@"修货/退货",@"删除订单",@"再次购买", nil];
    if (shopsInt == 1)
    {
        tArray = [NSArray arrayWithObjects:@"",@"订单追踪",@"确认收货", nil];
    }
    else if (shopsInt == 2)
    {
        tArray = [NSArray arrayWithObjects:@"",@"取消订单",@"去支付", nil];
    }
    else if (shopsInt == 3)
    {
        tArray = [NSArray arrayWithObjects:@"",@"删除订单",@"", nil];
    }
    for (int i = 0; i < 3; i++)
    {
        UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [addButton setFrame:CGRectMake(screenMySize.size.width*i/3, 0, screenMySize.size.width*1/3, barView.frame.size.height)];
        if (i == 0 || i == 2)
            [addButton setBackgroundColor:[UIColor colorWithRed:238/255.0 green:84/255.0 blue:84/255.0 alpha:1]];
        else
           [addButton setBackgroundColor:[UIColor grayColor]];
        [addButton setTitle:[tArray objectAtIndex:i] forState:UIControlStateNormal];
        [addButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [addButton addTarget:self action:@selector(settlementAction:) forControlEvents:UIControlEventTouchUpInside];
        addButton.tag = 100+i;
        [barView addSubview:addButton];
        if ([[tArray objectAtIndex:i] isEqualToString:@""]) {
            addButton.hidden = YES;
        }
    }

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1)
    {
        loading = [[LoadingView alloc] initWithFrame:self.view.frame];
        [self.view addSubview:loading];
        
        NSMutableDictionary *postDic = [[NSMutableDictionary alloc] init];
        [postDic setValue:[NSNumber numberWithInt:[[NSString stringWithFormat:@"%@",[allArray objectForKey:@"Id"]] intValue]] forKey:@"orderId"];
        
        if (alertTag ==1)
        {
            if (shopsInt == 0 || shopsInt == 3)//删除订单
            {
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                    NSDictionary *ret = [SendService SetCustomerDeleteStatus:postDic];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        NSLog(@"删除订单 %@",ret);
                        if ([[NSString stringWithFormat:@"%@",[ret objectForKey:@"Result"]] isEqualToString:@"success"])
                        {
                            [SendService alerViewMessage:@"删除订单成功。"];
                            [self.navigationController popViewControllerAnimated:YES];
                        }
                        else
                            [SendService alerViewMessage:[ret objectForKey:@"Message"]];
                        [loading closeLoading];
                    });
                });
            }
            else if (shopsInt == 1)//订单追踪
            {
                
            }
            else if (shopsInt == 2)//取消订单
            {
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                    NSDictionary *ret = [SendService CancelOrder:postDic];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        NSLog(@"取消订单 %@",ret);
                        if ([[NSString stringWithFormat:@"%@",[ret objectForKey:@"Result"]] isEqualToString:@"success"])
                        {
                            [SendService alerViewMessage:@"取消订单成功。"];
                            [self.navigationController popViewControllerAnimated:YES];
                        }
                        else
                            [SendService alerViewMessage:[ret objectForKey:@"Message"]];
                        [loading closeLoading];
                    });
                });
            }
            

        }
        else if (alertTag ==2)
        {
            if (shopsInt == 0)
            {
                NSMutableDictionary *postDic1 = [[NSMutableDictionary alloc] init];
                
                NSMutableArray *dic = [allArray objectForKey:@"Items"];
                
                for (int i = 0; i < dic.count; i ++)
                {
                    [postDic1 setObject:[[dic objectAtIndex:i] objectForKey:@"Id"] forKey:[NSString stringWithFormat:@"removefromcart%d",100+i]];
                }
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                    NSDictionary *myArray = [SendService CheckoutOrder:postDic1];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if (![[NSString stringWithFormat:@"%@",[myArray objectForKey:@"Result"]] isEqualToString:@"error"]) {
                            
                            SettlementViewController *details = [[SettlementViewController alloc] init];
                            details.allArray = myArray;
                            details.hidesBottomBarWhenPushed = YES;
                            [self.navigationController pushViewController:details animated:YES];
                        }
                        else
                        {
                            [SendService alerViewMessage:[myArray objectForKey:@"Message"]];
                        }
                        [loading closeLoading];
                        NSLog(@"结算 %@",myArray);
                    });
                });
            }
            else if (shopsInt == 1)
            {
                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                    NSDictionary *ret = [SendService SetAsDelivered:postDic];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        NSLog(@"确认收货 %@",ret);
                        if ([[NSString stringWithFormat:@"%@",[ret objectForKey:@"Result"]] isEqualToString:@"success"])
                        {
                            [SendService alerViewMessage:@"确认收货成功。"];
                            [self.navigationController popViewControllerAnimated:YES];
                            
                        }
                        else
                            [SendService alerViewMessage:[ret objectForKey:@"Message"]];
                        [loading closeLoading];
                    });
                });
            }
        }
    }
}
-(void)settlementAction:(id)sender
{
    int type = ((UIButton*)sender).tag-100;
    alertTag = type;
    if (type == 0)//修货/退货
    {
        
    }
    else if (type == 1)
    {
        if (shopsInt == 0 || shopsInt == 3)//删除订单
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"是否确定删除订单？"  delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是",nil];
            [alert show];
        }
        else if (shopsInt == 1)//订单追踪
        {
             
        }
        else if (shopsInt == 2)//取消订单
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"是否确定取消订单？"  delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是",nil];
            [alert show];
            
        }
        
    }
    else if (type == 2)
    {
        if (shopsInt == 0)//再次购买
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"是否确定再次购买？"  delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是",nil];
            [alert show];
            
        }
        else if (shopsInt == 1)//确认收货
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"是否确定收货？"  delegate:self cancelButtonTitle:@"否" otherButtonTitles:@"是",nil];
            [alert show];
            
        }
        else if (shopsInt == 2)//去支付
        {
            PayViewController *details = [[PayViewController alloc] init];
            details.hidesBottomBarWhenPushed = YES;
            details.allString = [allArray objectForKey:@"OrderTotal"];
            details.orderId = [allArray objectForKey:@"Id"];
            [self.navigationController pushViewController:details animated:YES];
        }
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    if (indexPath.section == 1)
    {
        
    }
    else if (indexPath.section ==2)
    {
        AllOrederListViewController *details = [[AllOrederListViewController alloc] init];
        details.dic = [allArray objectForKey:@"Items"];
        details.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:details animated:YES];

    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    shopsArray = [NSArray arrayWithObjects:@"完成",@"待收货",@"待付款",@"完成", nil];
    self.title = [shopsArray objectAtIndex:shopsInt];
    
    if (allArray.count > 0)
    {
        [mTableView reloadData];
        return;
    }
    loading = [[LoadingView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:loading];
    
    NSMutableDictionary *postDic = [[NSMutableDictionary alloc] init];
    [postDic setObject:idStr forKey:@"orderId"];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSDictionary *ret = [SendService GetOrderModelById:postDic];
        dispatch_async(dispatch_get_main_queue(), ^{
            allArray =  [ret objectForKey:@"Entity"];
            NSLog(@"店铺基本信息 %@",ret);
            [loading closeLoading];
            [mTableView reloadData];
        });
    });
}


#pragma mark -
#pragma mark Table View DataSource

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    //    if (section == 0)
    //        return 0.001;
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
        return 2;
    else if (section == 3)
        return 3;
    else if (section == 4)
        return 2;
    return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
            return shopsHight;
    }
    else if (indexPath.section == 3)
    {
        if (indexPath.row == 0)
            return shopsHight;
    }
    else if (indexPath.section == 4)
    {
        if (indexPath.row == 0)
            return settlementhight*1.5;
    }
    
    return settlementhight;
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ShopsmentCell";
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        aTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        aTableView.showsVerticalScrollIndicator = NO;
    }
    int i = (int)[[cell.contentView subviews] count] - 1;
    for(;i >= 0 ; i--)
    {
        [[[cell.contentView subviews] objectAtIndex:i] removeFromSuperview];
    }
    cell.backgroundColor = [UIColor whiteColor];
    
    
    if (indexPath.section == 0)
        return [self mCell:cell aCTableView:aTableView cellForRowAtIndexPath:indexPath];
    else if (indexPath.section == 1)
        return [self mCell:cell bCTableView:aTableView cellForRowAtIndexPath:indexPath];
    else if (indexPath.section == 2)
        return [self mCell:cell cCTableView:aTableView cellForRowAtIndexPath:indexPath];
    else if (indexPath.section == 3)
        return [self mCell:cell dCTableView:aTableView cellForRowAtIndexPath:indexPath];
    else if (indexPath.section == 4)
        return [self mCell:cell eCTableView:aTableView cellForRowAtIndexPath:indexPath];
    
    return cell;
}
- (UITableViewCell *)mCell:(UITableViewCell*)cell aCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (shopsHight-40)/2, screenMySize.size.width-30, 40) setTitle:[NSString stringWithFormat:@"订单号:%@",[allArray objectForKey:@"Id"]] setFont:labelSize setColor:[UIColor blackColor]]];
    }
    else if (indexPath.row == 1)
    {
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight/2-40)/2, screenMySize.size.width-30, 40) setTitle:@"您提交了订单，请等待系统确认" setFont:labelSize setColor:[UIColor blackColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight/2-40)/2+settlementhight/2, screenMySize.size.width-30, 40) setTitle:[NSString stringWithFormat:@"%@",[allArray objectForKey:@"OrderCreateDate"]] setFont:labelSize-1 setColor:[UIColor blackColor]]];
    }
    
    return cell;
}

- (UITableViewCell *)mCell:(UITableViewCell*)cell bCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, screenMySize.size.width,settlementhight)];
    [bgImageView setImage:[UIImage imageNamed:@"order_backg"]];
    [cell.contentView addSubview:bgImageView];
    
    
    UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20,15, 20,20)];
    [bg1ImageView setImage:[UIImage imageNamed:@"order_name"]];
    [cell.contentView addSubview:bg1ImageView];
    
    UIImageView *bg2ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(150,15, 20,20)];
    [bg2ImageView setImage:[UIImage imageNamed:@"order_phone"]];
    [cell.contentView addSubview:bg2ImageView];
    
    NSDictionary *AddressesDic = [allArray objectForKey:@"BillingAddress"];
    [cell.contentView addSubview:[self setFrame:CGRectMake(45,15, 100,20) setTitle:[NSString stringWithFormat:@"%@",[AddressesDic objectForKey:@"Name"]] setFont:labelSize-1 setColor:[UIColor blackColor]]];

    [cell.contentView addSubview:[self setFrame:CGRectMake(175,15, screenMySize.size.width-195,20) setTitle:[NSString stringWithFormat:@"%@",[AddressesDic objectForKey:@"CellphoneNumber"]] setFont:labelSize-1 setColor:[UIColor blackColor]]];

    [cell.contentView addSubview:[self setFrame:CGRectMake(20,45, screenMySize.size.width-40,settlementhight-50-10) setTitle:[NSString stringWithFormat:@"%@%@%@%@%@",[AddressesDic objectForKey:@"StateProvinceName"],[AddressesDic objectForKey:@"CityName"],[AddressesDic objectForKey:@"DistrictName"],[AddressesDic objectForKey:@"StreetName"],[AddressesDic objectForKey:@"Address1"]] setFont:labelSize+1 setColor:[UIColor blackColor]]];
    
    return cell;
}

- (UITableViewCell *)mCell:(UITableViewCell*)cell cCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSMutableArray *dic = [allArray objectForKey:@"Items"];
    if (dic.count > 1)
    {
        int Hight = 0;
        
        UIScrollView *ta1ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, self.view.bounds.size.width,settlementhight)];
        ta1ScrollView.backgroundColor = [UIColor clearColor];
        [ta1ScrollView setPagingEnabled:NO];
        [ta1ScrollView setShowsHorizontalScrollIndicator:NO];
        [cell.contentView addSubview:ta1ScrollView];
        //解决UIScrollView把uitableviewcell的点击事件屏蔽start
        ta1ScrollView.userInteractionEnabled = NO;
        [ta1ScrollView addGestureRecognizer:ta1ScrollView.panGestureRecognizer];
        //解决UIScrollView把uitableviewcell的点击事件屏蔽end
        
        [ta1ScrollView setContentSize:CGSizeMake(self.view.bounds.size.width*dic.count/3,settlementhight)];
        
        for (int i = 0; i < dic.count; i ++)
        {
            
            UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10+i*(settlementhight-15),Hight+10, settlementhight-20,settlementhight-20)];
            [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[dic objectAtIndex:i] objectForKey:@"ProdcutPictureUrl"]]]];
            bgImageView.contentMode =  UIViewContentModeScaleAspectFit;
            //    bgImageView.contentMode = UIViewContentModeScaleAspectFill;
            [ta1ScrollView addSubview:bgImageView];
            
            UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(9.5+i*(settlementhight-15),Hight+9.5, settlementhight-19,settlementhight-19)];
            [bg1ImageView setImage:[UIImage imageNamed:@"gwckk"]];
            [ta1ScrollView addSubview:bg1ImageView];
        }
 
    }
    else
    {
        int Hight = 0;
        
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,Hight+10, settlementhight-20,settlementhight-20)];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[dic objectAtIndex:indexPath.row] objectForKey:@"ProdcutPictureUrl"]]]];
        bgImageView.contentMode =  UIViewContentModeScaleAspectFit;
        //    bgImageView.contentMode = UIViewContentModeScaleAspectFill;
        [cell.contentView addSubview:bgImageView];
        
        UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(9.5,Hight+9.5, settlementhight-19,settlementhight-19)];
        [bg1ImageView setImage:[UIImage imageNamed:@"gwckk"]];
        [cell.contentView addSubview:bg1ImageView];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(settlementhight, Hight+10, screenMySize.size.width-settlementhight-80, 50) setTitle:[NSString stringWithFormat:@"%@",[[dic objectAtIndex:indexPath.row] objectForKey:@"ProductName"]] setFont:labelSize setColor:[UIColor blackColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(settlementhight, Hight+10+50, screenMySize.size.width-settlementhight-80, 20) setTitle:[NSString stringWithFormat:@"x%@",[[dic objectAtIndex:indexPath.row] objectForKey:@"Quantity"]] setFont:labelSize setColor:[UIColor blackColor]]];
        
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(screenMySize.size.width-80, settlementhight/2-10, 80, 20) setTitle:[NSString stringWithFormat:@"%@",[[dic objectAtIndex:indexPath.row] objectForKey:@"UnitPrice"]] setFont:labelSize setColor:[UIColor redColor]]];
        
    }
    
    return cell;
}


- (UITableViewCell *)mCell:(UITableViewCell*)cell dCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (shopsHight-40)/2, screenMySize.size.width-30, 40) setTitle:@"支付方式" setFont:labelSize setColor:[UIColor grayColor]]];

        [cell.contentView addSubview:[self setFrame:CGRectMake(80, (shopsHight-40)/2, screenMySize.size.width-105, 40) set1Title:@"在线支付" setFont:labelSize setColor:[UIColor blackColor]]];
    }
    else if (indexPath.row == 1)
    {
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight/2-40)/2, screenMySize.size.width-30, 40) setTitle:@"配送方式" setFont:labelSize setColor:[UIColor grayColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight/2-40)/2+settlementhight/2, screenMySize.size.width-30, 40) setTitle:@"送货日期:只工作日送货(双休日、节假日不用送)" setFont:labelSize-1 setColor:[UIColor grayColor]]];
    }
    else if (indexPath.row == 2)
    {
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight/3-40)/2, screenMySize.size.width-30, 40) setTitle:@"发票信息" setFont:labelSize setColor:[UIColor grayColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(80, (settlementhight/3-40)/2, screenMySize.size.width-105, 40) set1Title:@"纸质发票" setFont:labelSize setColor:[UIColor blackColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight/3-40)/2+settlementhight/3, screenMySize.size.width-30, 40) setTitle:@"发票抬头:个人" setFont:labelSize setColor:[UIColor grayColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight/3-40)/2+settlementhight*2/3, screenMySize.size.width-30, 40) setTitle:@"发票内容:明细" setFont:labelSize setColor:[UIColor grayColor]]];
    }
   return cell;
}


- (UITableViewCell *)mCell:(UITableViewCell*)cell eCTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)
    {
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight*1.5/5-40)/2, screenMySize.size.width-30, 40) setTitle:@"商品总额" setFont:labelSize setColor:[UIColor grayColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(80, (settlementhight*1.5/5-40)/2, screenMySize.size.width-105, 40) set1Title:[NSString stringWithFormat:@"¥%@",[allArray objectForKey:@"OrderSubtotal"]] setFont:labelSize setColor:[UIColor redColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight*1.5/5-40)/2+settlementhight*1.5/5, screenMySize.size.width-30, 40) setTitle:@"-优惠券" setFont:labelSize setColor:[UIColor grayColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(80, (settlementhight*1.5/5-40)/2+settlementhight*1.5/5, screenMySize.size.width-105, 40) set1Title:[NSString stringWithFormat:@"¥%@",[allArray objectForKey:@"CouponTotalPrice"]] setFont:labelSize setColor:[UIColor redColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight*1.5/5-40)/2+settlementhight*1.5*2/5, screenMySize.size.width-30, 40) setTitle:@"-元宝" setFont:labelSize setColor:[UIColor grayColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(80, (settlementhight*1.5/5-40)/2+settlementhight*1.5*2/5, screenMySize.size.width-105, 40) set1Title:[NSString stringWithFormat:@"¥%@",[allArray objectForKey:@"ConsumptionIntegralPrice"]] setFont:labelSize setColor:[UIColor redColor]]];
        
        
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight*1.5/5-40)/2+settlementhight*1.5*3/5, screenMySize.size.width-30, 40) setTitle:@"-返现" setFont:labelSize setColor:[UIColor grayColor]]];
        
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(80, (settlementhight*1.5/5-40)/2+settlementhight*1.5*3/5, screenMySize.size.width-105, 40) set1Title:[NSString stringWithFormat:@"¥0.00"] setFont:labelSize setColor:[UIColor redColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight*1.5/5-40)/2+settlementhight*1.5*4/5, screenMySize.size.width-30, 40) setTitle:@"+运费" setFont:labelSize setColor:[UIColor grayColor]]];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(80, (settlementhight*1.5/5-40)/2+settlementhight*1.5*4/5, screenMySize.size.width-105, 40) set1Title:[NSString stringWithFormat:@"¥%@",[allArray objectForKey:@"OrderShipping"]] setFont:labelSize setColor:[UIColor redColor]]];
    }
    else if (indexPath.row == 1)
    {
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight/2-40)/2, screenMySize.size.width-30, 40) setTitle:@"实付款" setFont:labelSize+5 setColor:[UIColor blackColor]]];
        
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(80, (settlementhight/2-40)/2, screenMySize.size.width-105, 40) set1Title:[NSString stringWithFormat:@"¥%@",[allArray objectForKey:@"OrderTotal"]] setFont:labelSize+5 setColor:[UIColor redColor]]];
//        NSString * endTime = [[allArray objectForKey:@"OrderNotes"] objectForKey:@"CreatedOn"];
//        endTime =  [endTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(10, (settlementhight/2-40)/2+settlementhight/2, screenMySize.size.width-30, 40) set1Title:[NSString stringWithFormat:@"下单时间:%@",[allArray objectForKey:@"OrderCreateDate"]] setFont:labelSize-1 setColor:[UIColor grayColor]]];
    }
    return cell;
}

-(UILabel*)setFrame:(CGRect)frame setTitle:(NSString*)title setFont:(int)font setColor:(UIColor*)myColor
{
    title = [title stringByReplacingOccurrencesOfString:@"<null>" withString:@""];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame];
    if (title != nil)
        titleLabel.text = [NSString stringWithFormat:@"%@",title];
    titleLabel.textAlignment = 0;
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont fontWithName:@"Arial" size:font];
    titleLabel.textColor = myColor;
    return titleLabel;
}

-(UILabel*)setFrame:(CGRect)frame set1Title:(NSString*)title setFont:(int)font setColor:(UIColor*)myColor
{
    title = [title stringByReplacingOccurrencesOfString:@"<null>" withString:@""];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame];
    if (title != nil)
        titleLabel.text = [NSString stringWithFormat:@"%@",title];
    titleLabel.textAlignment = 2;
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont fontWithName:@"Arial" size:font];
    titleLabel.textColor = myColor;
    return titleLabel;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
  
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
